package com.tiger.cloud.common.mapper;

import java.io.IOException;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;

public class TriangleAppObjectMapper extends ObjectMapper {

	private static final long serialVersionUID = 1L;

	public TriangleAppObjectMapper() {
		DefaultSerializerProvider.Impl sp = new DefaultSerializerProvider.Impl();
		sp.setNullValueSerializer(new ExampleSerializer());
		this.setSerializerProvider(sp);
		setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
		// disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
		disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
	}

	public class ExampleSerializer extends JsonSerializer<Object> {
		public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
			jgen.writeNull();
		}
	}
}